/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.agent.service;

import cn.ac.iie.agent.tools.HdfsTools;
import java.io.Serializable;
import org.apache.log4j.Logger;

/**
 *
 * @author root
 */
public class LocalThreadPoolTask implements Runnable, Serializable {

    private static Logger logger = Logger.getLogger(LocalThreadPoolTask.class);
    private String name;
    private String hdfsPath;
    private String localFilePath;
    private String subjobid;
    private HdfsUploadService hdfsUploadService;

    public LocalThreadPoolTask(String name, String localFilePath, String hdfsPath, String subjobid, HdfsUploadService hdfsUploadService) {
        this.name = name;
        this.localFilePath = localFilePath;
        this.hdfsPath = hdfsPath;
        this.subjobid = subjobid;
        this.hdfsUploadService = hdfsUploadService;
    }

    public void run() {
        HdfsTools hdfsTools = new HdfsTools();
        boolean flag = hdfsTools.put(localFilePath, hdfsPath, subjobid);
        if (!flag) {
            hdfsUploadService.changeDesc(subjobid + " " + localFilePath + " hdfs put error!");
            hdfsUploadService.changeStatus("fail");
            logger.info(subjobid + " " + localFilePath + " hdfs put error!");
        } else {
            hdfsUploadService.changeStatus("sucess");
            hdfsUploadService.plusSucessUploadFileNumber();
            logger.info(subjobid + " " + localFilePath + " hdfs put sucess");
        }
    }

    /**
     * @return the hdfsPath
     */
    public String getHdfsPath() {
        return hdfsPath;
    }

    /**
     * @param hdfsPath the hdfsPath to set
     */
    public void setHdfsPath(String hdfsPath) {
        this.hdfsPath = hdfsPath;
    }
}
